import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/doctor_patrol/doctor_patorl_api.dart';
import 'package:ls_work/doctor_patrol/response/doctor_patrol_record_list.dart';

class DoctorPatrolModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  ///巡诊记录列表
  Future<List<DoctorPatrolRecordList>> patrolRecord(
      {String? finishDateFin1,
      String? finishDateFin2,
      String? executor,
      bool timeReverseOrder = true,
      bool allDate = true,
        int page = 1,
        int rows = 20,
      int planType = 5}) async {
    var map = {
      "finishDateFin1":finishDateFin1,
      "finishDateFin2":finishDateFin2,
      "executor":executor,
      "timeReverseOrder":timeReverseOrder,
      "allDate":allDate,
      "planType":planType,
      "page":page,
      "rows":rows,
    };
    map.removeWhere((key,value)=>value==null);
    var data = await HttpGo.instance.postData(DoctorPatrolApi.patrolRecordList,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      return ((data['data']['rows'] as List?)??[]).map((e)=>DoctorPatrolRecordList.fromJson(e)).toList();
    }else{
      throw data['msg'];
    }
  }

  ///新增、更新巡诊
  Future<Map> addPatrolInfo(SubmitDoctorPatrolData info) async {
    var map = info.toJson();
    map.removeWhere((key,value)=>value==null);
    var url = info.id!=null?DoctorPatrolApi.updatePatrol:DoctorPatrolApi.createPatrol;
    var data = await HttpGo.instance.postData(url,data: map,options: Options(contentType: Headers.jsonContentType));
    if("0"==data['code']){
      return data;
    }else{
      throw data['msg'];
    }
  }

}


class SubmitDoctorPatrolData{
  String? attachIds;
  List<dynamic> attachList;
  dynamic customerElderId;
  String? finishTime;
  dynamic hrId;
  dynamic id;
  int isNurseCheck = 1;
  String? remark;
  SubmitDoctorPatrolHealth? healthReport;

  SubmitDoctorPatrolData(
      {this.attachIds,
      this.attachList = const [],
      this.customerElderId,
      this.finishTime,
      this.hrId,
      this.id,
      this.isNurseCheck = 1,
      this.remark,
      this.healthReport});

  factory SubmitDoctorPatrolData.fromJson(Map<String, dynamic> json) {
    return SubmitDoctorPatrolData(
      attachIds: json['attachIds'],
      attachList: json['attachList'],
      customerElderId: json['customerElderId'],
      finishTime: json['finishTime'],
      hrId: json['hrId'],
      id: json['id'],
      isNurseCheck: json['isNurseCheck'],
      remark: json['remark'],
      healthReport: SubmitDoctorPatrolHealth.fromJson(json['healthReport']),
    );
  }

  Map<String, dynamic> toJson() => {
        'attachIds': attachIds,
        'attachList': attachList.map((e) => e.toJson()).toList(),
        'customerElderId': customerElderId,
        'finishTime': finishTime,
        'hrId': hrId,
        'id': id,
        'isNurseCheck': isNurseCheck,
        'remark': remark,
        'healthReport': healthReport?.toJson(),
      };
}

class SubmitDoctorPatrolHealth{
  num? breathe;
  num? heart;
  num? high;
  num? low;
  num? oxygen;
  num? pulseRate;
  num? temperature;


  SubmitDoctorPatrolHealth(
      {this.breathe,
      this.heart,
      this.high,
      this.low,
      this.oxygen,
      this.pulseRate,
      this.temperature});

  factory SubmitDoctorPatrolHealth.fromJson(Map<String, dynamic> json) {
    return SubmitDoctorPatrolHealth(
      breathe: json['breathe'],
      heart: json['heart'],
      high: json['high'],
      low: json['low'],
      oxygen: json['oxygen'],
      pulseRate: json['pulseRate'],
      temperature: json['temperature'],
    );
  }

  Map<String, dynamic> toJson() => {
        'breathe': breathe,
        'heart': heart,
        'high': high,
        'low': low,
        'oxygen': oxygen,
        'pulseRate': pulseRate,
        'temperature': temperature,
      };
}